from flask import Flask
from flask_cors import CORS
from models import db
from views.users import user_bp
from views.channel import channel_bp
from common.uitils.jwt_auth import jwt_authentication
from views.comments import comment_bp


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cors = CORS(app)
    db.init_app(app)
    # 注册蓝图接口路由
    app.register_blueprint(user_bp)
    app.register_blueprint(channel_bp)
    app.register_blueprint(comment_bp)
    # 使用钩子验证token
    app.before_request(jwt_authentication)

    return app
